local CheckWidgetType = UI.CheckWidgetType
local CheckArgType = UI.CheckArgType
local CheckArgWidget = UI.CheckArgWidget
local MakeAccessor = UI.MakeAccessor
local MakeTypeSetter = UI.MakeTypeSetter

--[[ ScrollingMessageFrame @FIXME ]]--
local ScrollingMessageFrame = UI.NewWidgetType("ScrollingMessageFrame", {"Frame", "FontInstance"})
ScrollingMessageFrame.parameters = {
	data = {},
	maxlines = 25,
}

function ScrollingMessageFrame:Initialize(o)
	local t = UI.params[o]
	assert(t)
end

function ScrollingMessageFrame.prototype:AtBottom()
	CheckWidgetType("ScrollingMessageFrame:AtBottom", self, "ScrollingMessageFrame")
	return true
end

MakeTypeSetter("ScrollingMessageFrame", "SetMaxLines", "maxlines", "number")
MakeAccessor("ScrollingMessageFrame", "GetMaxLines", "maxlines")

function ScrollingMessageFrame.prototype:AddMessage(text)
	CheckWidgetType("ScrollingMessageFrame:AddMessage", self, "ScrollingMessageFrame")
	local t = UI.params[self]
	table.insert(t.data, 1, text)
	t.data[t.maxlines + 1] = nil
	log("II AddMessage: %q", text)
end

function ScrollingMessageFrame.prototype:Clear()
	CheckWidgetType("ScrollingMessageFrame:Clear", self, "ScrollingMessageFrame")
end

UI.RegisterScriptHandlers(ScrollingMessageFrame,
	"OnHyperlinkClick", "OnHyperlinkEnter", "OnHyperlinkLeave")

function ScrollingMessageFrame.prototype:SetFading(state)
	CheckWidgetType("ScrollingMessageFrame:SetFading", self, "ScrollingMessageFrame")
	UI.params[self].fading = state and true or false
end

function ScrollingMessageFrame.prototype:ScrollUp()
	CheckWidgetType("ScrollingMessageFrame:ScrollUp", self, "ScrollingMessageFrame")
end

function ScrollingMessageFrame.prototype:UpdateColorByID(id, r, g, b)
	CheckWidgetType("ScrollingMessageFrame:UpdateColorByID", self, "ScrollingMessageFrame")
end

function ScrollingMessageFrame.prototype:SetHyperlinksEnabled(flags)
	CheckWidgetType("ScrollingMessageFrame:SetHyperlinksEnabled", self, "ScrollingMessageFrame")
end
